//
//  ShelfTableViewCell.m
//  WashForU
//
//  Created by 王俊 on 15/12/2.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "ShelfTableViewCell.h"

@interface ShelfTableViewCell()
@property(nonatomic,strong)UIImageView *backgroundImage;
@property(nonatomic,strong)UIImageView *clotheImage;
@property(nonatomic,strong)UILabel     *titleLabel;
@property(nonatomic,strong)UILabel     *priceLabel;
@property(nonatomic,strong)UILabel     *multiLabel;
@property(nonatomic,strong)UIButton    *deleteButton;

@end

@implementation ShelfTableViewCell

- (instancetype)initWithData:(ClotheInCart*) data
{
    if (self = [super init]){
        self.cellInfo = data;
        self.counter = [Counter alloc];
        self.counter.numb = data.numb;
        
        
        
        [self setUpView];
        [self addCustomConstrain];
    }
    return self;
    
}

- (void)setUpView
{
    self.counter         = [self.counter initView];
    self.backgroundImage = [[UIImageView alloc]init];
    self.clotheImage     = [[UIImageView alloc]init];
    self.deleteButton    = [[UIButton alloc]init];
    self.titleLabel      = [[UILabel alloc]init];
    self.priceLabel      = [[UILabel alloc]init];
    self.multiLabel      = [[UILabel alloc]init];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    self.backgroundImage.image = [UIImage imageNamed:self.cellInfo.clotheData.backgroundImageName];
    NSLog(@"BackImageName:%@",self.cellInfo.clotheData.backgroundImageName);
    NSLog(@"ImageName:%@",self.cellInfo.clotheData.imageName);
    self.clotheImage.image     = [UIImage imageNamed:self.cellInfo.clotheData.imageName];
    [self.deleteButton setImage:@"删除图标" andHighlightedImage:@"删除图标H"];
    [self.titleLabel setText:self.cellInfo.clotheData.title andFont:[UIFont CustomFont:20] andColor:[UIColor GrayColor_88] andAligm:NSTextAlignmentCenter];
    [self.priceLabel setText:[NSString stringWithFormat:@"￥%d",self.cellInfo.clotheData.price] andFont:[UIFont boldSystemFontOfSize:17] andColor:[UIColor CustomOrangeColor] andAligm:NSTextAlignmentCenter];
    [self.multiLabel setText:@"x" andFont:[UIFont boldSystemFontOfSize:15] andColor:[UIColor GrayColor_142] andAligm:NSTextAlignmentCenter];
    
    [self addSubview:self.counter];
    [self addSubview:self.backgroundImage];
    [self addSubview:self.deleteButton];
    [self addSubview:self.clotheImage];
    [self addSubview:self.titleLabel];
    [self addSubview:self.priceLabel];
    [self addSubview:self.multiLabel];

    
    
}
- (void)addCustomConstrain
{
    [self.backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.top.equalTo(self).offset(10);
        make.leading.equalTo(self).offset(15);
        make.bottom.equalTo(self).offset(-10);
        make.width.equalTo(self.backgroundImage.mas_height).multipliedBy(110.0/125.0);
    }];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(self.backgroundImage).offset(10);
        make.bottom.trailing.equalTo(self.backgroundImage).offset(-10);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backgroundImage);
        make.leading.equalTo(self.backgroundImage.mas_trailing).offset(10);
        make.height.mas_equalTo(30);
        
    }];
    [self.clotheImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.backgroundImage);
        make.height.width.equalTo(self.backgroundImage).offset(-10);
    }];
    [self.counter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(95, 25));
        make.centerY.equalTo(self).offset(10);
        make.trailing.equalTo(self).offset(-75);
    }];
    [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(18, 18));
        make.trailing.equalTo(self).offset(-5);
        make.top.equalTo(self).offset(5);
    }];
    [self.multiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.centerY.equalTo(self.counter).offset(1);
        make.leading.equalTo(self.counter.mas_trailing);
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.top.equalTo(self.counter);
        make.leading.equalTo(self.multiLabel.mas_trailing);
    }];
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

}

@end
